#include <stdio.h>
#include<iostream>
#include "gPTP/ptp.h"
#include "tsmp/tsmp.h"
#include "../../../../../../usr/include/netinet/in.h"

// 创建一个TSNConfig结构体实例
TSNConfig config;
char *NET_INIT;

int main(int argc, char *argv[])
{
    if (argc < 2) {
        std::cout << "please give me more parameters" << std::endl;
        return 1;
    }
    NET_INIT = argv[1];
    // 读取TSN配置
    std::string ss = "config/gPTPconfig.xml";
    if (!readTSNConfig(ss, config))
    {
        return -1;
    }
    // 全局时钟置零
    uint32_t _init_local_clock[2] = {0, 0};
    writeReqSend(0x00080004, 2, _init_local_clock);
    init_info_sync();
    init_info_pdelay();
    if (config.gm_flag)
    {
        printf("----------------start------------------\n");
        timer_fun_sync(3);
    }
    else
    {
        uint32_t rale[1] = {htonl(0x00000001)};
        writeReqSend(0x40000000, 1, rale); // set slave_role_reg
    }

    printf("----------------start------------------\n");

    timer_fun_pdelay(2);
    packRec(config.gm_flag);

    return 0;
}